﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Subsidiary.CouponWrapper;

namespace Subsidiary
{
    public partial class CouponForm : UserControl
    {
        public CouponForm()
        {
            InitializeComponent();
            InitCombo();
        }

        void InitCombo()
        {
            cobSite.DataSource = WebSite.GetWebSites();
            cobSite.DisplayMember = "Name";
            cobSite.ValueMember = "Code";
        }

        class WebSite
        {
            public string Name { get; set; }
            public string Code { get; set; }

            public static List<WebSite> GetWebSites()
            {
                return new List<WebSite>
            {                
                new WebSite{Code="360buy",Name="京东"},
                new WebSite{Code="vjia",Name="VJIA"},
                new WebSite{Code="etao",Name="E淘"},
                new WebSite{Code="1haodian",Name="1号店"},
                new WebSite{Code="dangdang",Name="当当"},
                new WebSite{Code="vancl",Name="凡客"}
            };
            }
        }

        private void btnGet_Click(object sender, EventArgs e)
        {
            CouponFacade.PickUp(cobSite.SelectedValue.ToString(), tbHTML.Text);
            MessageBox.Show("完成");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            tbHTML.Text = tbHTML.Text.Replace("\r", "").Replace("\n", "");
        }

        private void tbHTML_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
            {
                ((TextBox)sender).SelectAll();
            }  
        }
    }
}
